package main

import (
	"log"
	"net/http"
	"os"
	"path"
	"time"
	// "string"
)

var (
	AppName  string
	AppPath  string
	DbName   string
	Viewpath string
)

// 为 myHandle 实现 func route 底层
var mux map[string]ControllerInterface

func route() {
	mux = make(map[string]ControllerInterface)
	mux["/"] = &OrderController{}
	mux["/menu"] = &MenuController{}
}

func init() {
	AppName = "Dian Can"
	DbName = "./orders.db"
	Viewpath = "./view/"

	os.Chdir(path.Dir(os.Args[0]))
	AppPath, _ = os.Getwd()
	log.Print("On ", AppPath, "\n")
}

func main() {
	route()
	myServer := http.Server{
		Addr:        ":4000",
		Handler:     &Router{},
		ReadTimeout: 5 * time.Second,
	}

	// http.Handle("/static/",
	// 	http.StripPrefix("/static/",
	// 		http.FileServer(http.Dir(AppPath))))

	log.Print("访问 http://localhost:4000/ 开始...\n")
	err := myServer.ListenAndServe()
	checkErr(err)
}

// TODO : 	config.json 读取
// TODO :	static file 服务
